package com.zzyl.nursing.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.member.domain.Reservation;
import com.zzyl.nursing.member.dto.MemberProjectDto;
import com.zzyl.nursing.member.mapper.MemberProjectMapper;
import com.zzyl.nursing.member.service.MemberProjectService;
import com.zzyl.nursing.member.vo.MemberProjectVo;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class MemberProjectServiceImpl implements MemberProjectService {

    @Autowired
    private MemberProjectMapper memberProjectMapper;

    @Override
    public MemberProjectVo page(MemberProjectDto dto) {
        String name = dto.getName();
        Integer status = dto.getStatus();
        Integer pageSize = dto.getPageSize();
        Integer pageNum = dto.getPageNum();
        Page<NursingProject> page = new Page<>(pageNum, pageSize);

        LambdaQueryWrapper<NursingProject> wrapper = new LambdaQueryWrapper<NursingProject>()
                .like(name != null, NursingProject::getName, name)
                .eq(status != null, NursingProject::getStatus, status);

        page = memberProjectMapper.selectPage(page, wrapper);
        return new MemberProjectVo(page.getTotal(), page.getRecords());
    }

    @Override
    public NursingProject select(Integer id) {
        log.info("查询id为{}的护理项目", id);
        LambdaQueryWrapper<NursingProject> wrapper = new LambdaQueryWrapper<NursingProject>().eq(NursingProject::getId, id);
        return memberProjectMapper.selectOne(wrapper);
    }
}
